package com.wei.controller;


import com.wei.entity.GdEquipment;
import com.wei.mapper.GdEquipmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李泽伟
 * @since 2022-03-08
 */
@RestController
@RequestMapping
public class GdEquipmentController {
    
    @Autowired
    private GdEquipmentMapper equipmentMapper;

    @RequestMapping("/getEquipment")
    public List<GdEquipment> getEquipment(){
        Map<String, Object> map = new HashMap<>();
        map.put("deleted", 0);
        List<GdEquipment> properties=equipmentMapper.selectByMap(map);
        return properties;
    }

    @RequestMapping("/addEquipment")
    public void setEquipment(@RequestParam Map<String,Object> equipmentObj){
        GdEquipment Equipment =setParam(equipmentObj);
        equipmentMapper.insert(Equipment);
    }

    @RequestMapping("/updateEquipment")
    public void updateEquipment(@RequestParam Map<String,Object> equipmentObj){
        GdEquipment Equipment = setParam(equipmentObj);
        equipmentMapper.updateById(Equipment);
    }

    @RequestMapping("/deleteEquipment")
    public void deleteEquipment(@RequestParam String equipmentId){
        equipmentMapper.deleteById(equipmentId);
    }

    /**
     * 设置参数方法
     * @param EquipmentObj
     * @return
     */
    private GdEquipment setParam(@RequestParam Map<String, Object> EquipmentObj) {
        GdEquipment equipment=new GdEquipment();
        equipment.setEquipmentId((String) EquipmentObj.get("equipmentId"));
        equipment.setEquipmentName((String) EquipmentObj.get("equipmentName"));
        equipment.setEquipmentType((String) EquipmentObj.get("equipmentBrand"));
        equipment.setEquipmentBrand((String) EquipmentObj.get("equipmentType"));
        equipment.setEquipmentBuydate((String) EquipmentObj.get("equipmentBuydate"));
        equipment.setEquipmentPrice( Double.parseDouble(EquipmentObj.get("equipmentPrice").toString()));
        equipment.setEquipmentQuantity( Integer.parseInt(EquipmentObj.get("equipmentQuantity").toString()));
        return equipment;
    }

}

